package com.ybkj.daijia.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.ybkj.daijia.Setting;
import com.ybkj.daijia.common.Result;
import com.ybkj.daijia.server.freight.Order;
import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.HttpServerErrorException;
import org.springframework.web.client.RestTemplate;

@Component
public class FreightApi {

    /**
     * 创建货运订单
     */
    public static final String CREATE_ORDER = "api/orders/create";
    /**
     * 查询货运订单
     */
    public static final String QUERY_ORDER = "api/orders";
    /**
     * 查询货运新订单
     */
    public static final String QUERY_NEWORDERS = "api/orders/newOrders";
    /**
     * 查询执行中货运订单
     */
    public static final String QUERY_EXEORDER = "api/orders/findExceOrder";
    /**
     * 型查询货运订单
     */
    public static final String QUERY_ORDERLIST = "api/orders/orderlist";
    /**
     * 型查询司机评价
     */
    public static final String QUERY_ORDEREVIEW = "api/orderReview/findByDriver";
    public static final String QUERY_ORDEREVIEW_ONE = "api/orderReview/findOne";
    public static final String DELETE_ORDEREVIEW = "api/orderReview/deleteById";
    /**
     * 查询拒单记录
     */
    public static final String QUERY_REFUSEORDERLIST = "api/orderRefuse/refuseData";
    /**
     * 查询单个货车类型
     */
    public static final String QUERY_ONE_TRUCKTYPE = "api/truckType/findByTruckTypeId";
    /**
     * 新的查询单个货车类型
     */
    public static final String NEW_QUERY_ONE_TRUCKTYPE = "api/truckType/v4/findByTruckTypeIdAndCompany";
    /**
     * 取消货运订单
     */
    public static final String CANCEL_ORDER = "api/orders/update";
    /**
     * 收回货运订单
     */
    public static final String CALLBACK = "api/orders/update";
    /**
     * 根据订单ID查询途径地
     */
    public static final String QUERY_WAYPOINT = "api/waypoint/findByOrderId";
    /**
     * 条件查询货车类型
     */
    public static final String QUERY_TRUCKTYPE = "api/truckType/findByParams";
    /**
     * 条件查询货车类型
     */
    public static final String NEW_QUERY_TRUCKTYPE = "api/truckType/v4/findByParams";
    /**
     * 查询服务人员的货运订单
     */
    public static final String FIND_MYWORK = "api/orders/findMyWork";
    /**
     * 条件查询货车
     */
    public static final String QUERY_PARAMS_TRUCKS = "api/truck/findByParams";
    /**
     * 创建货车
     */
    public static final String CREATE_TRUCK = "api/truck/create";
    /**
     * 删除货车
     */
    public static final String DELETE_TRUCK = "api/truck/delete";
    /**
     * 查询单个货车
     */
    public static final String QUERY_TRUCK = "api/truck/findByTruckId";
    /**
     * 根据货车车牌查询货车
     */
    public static final String QUERY_TRUCK_CARNUMBER = "api/truck/findByCarNumber";
    /**
     * /** 修改单个货车
     */
    public static final String UPDATE_TRUCK = "api/truck/update";
    /**
     * 公司名字查询货车类型
     */
    public static final String QUERY_TRUCKTYPE_COMPANY = "api/truckType/findByCompanyName";
    /**
     * 查询已开通的类型
     */
    public static final String QUERY_TRUCKTYPECOMPANY = "api/truckType/v4/findTruckTypeCompanyByCompanyName";
    /**
     * 修改已开通的公司对应收费
     */
    public static final String UPDATE_TRUCKTYPE_COMPANY_AREA = "api/truckType/v4/updateTruckTypeCompanyArea";
    /**
     * 删除货车类型
     */
    public static final String DELETE_TRUCKTYPE = "api/truckType/delete";
    /**
     * 取消开通车型
     */
    public static final String CANCEL_TRUCKTYPE_COMPANY = "api/truckType/v4/cancelTruckType";
    /**
     * 删除货车类型
     */
    public static final String NEW_DELETE_TRUCKTYPE = "api/truckType/v4/delete";
    /**
     * 添加货车类型
     */
    public static final String CREATE_TRUCKTYPE = "api/truckType/create";
    /**
     * 添加货车类型
     */
    public static final String NEW_CREATE_TRUCKTYPE = "api/truckType/v4/create";
    /**
     * 修改货车类型
     */
    public static final String UPDATE_TRUCKTYPE = "api/truckType/update";
    /**
     * 修改货车类型
     */
    public static final String NEW_UPDATE_TRUCKTYPE = "api/truckType/v4/update";
    /**
     * 修改金额
     */
    public static final String UPDATE_REALMONEY = "api/orders/v4/updateRealMoney";
    /**
     * 开通类型
     */
    public static final String SUBSCRIBETRUCKTYPE = "api/truckType/v4/subscribeTruckType";
    /**
     * 查询货车订单(单个)
     */
    public static final String QUERY_ORDER_ONE = "api/orders/findByOrderId";
    /**
     * 添加订单备注
     */
    public static final String CREATE_ORDERMEMO = "api/orderMemo/remark";
    /**
     * 查询催单
     */
    public static final String QUERY_CUIDAN = "api/orders/getHastenOrder";
    /**
     * 关闭催单
     */
    public static final String CLOSE_CUIDAN = "api/orders/closeHasten";
    /**
     * 派单
     */
    public static final String PAIDAN_ORDER = "api/orders/update";
    /**
     * 货运订单统计(年)
     */
    public static final String ORDERSTATISTICS = "api/orders/freightDataForYear";
    /**
     * 货运订单统计(月)
     */
    public static final String ORDERSTATISTICSMONTH = "api/orders/freightDataForMonth";
    /**
     * 货运订单统计(日)
     */
    public static final String ORDERSTATISTICSDAY = "api/orders/freightDataForDay";
    /**
     * 根据司机id查询明细
     */
    public static final String DRIVERORDERDETAILVO = "api/orders/driverOrderDetailVo";
    public static final String DRIVERORDERDETAILCOUNT = "api/orders/driverOrderDetailCount";
    public static final String FREIGHTHEATMAP = "api/orders/freightHeatMap";
    public static final String FREIGHTMEMBERORDER = "api/orders/freightMemberOrder";
    /**
     * 货运订单类型统计
     */
    public static final String ORDERTYPESTATISTICS = "api/orders/orderFromSource";
    public static final String DRIVERACHIEVEMENT = "api/orders/driverAchievement";
    /**
     * 货运订单汇总
     */
    public static final String COMPOSITIVE = "api/orders/chart";
    /**
     * 按时间查询全部公司的专车订单统计
     */
    public static final String COMPANYORDERSTATISTICS = "api/orders/companyOrder";
    public static final String FINISH_TASK = "api/orders/finishTask";
    public static final String CONFIRM_TASK = "api/orders/confirmTask";
    public static final String CREATE_PAYRECORDORDER = "api/payRecordOrder/create";
    public static final String QUERY_PAYRECORDORDER_ONE = "api/payRecordOrder/findOne";
    public static final String TREATMENT_PAYRECORDORDER = "api/payRecordOrder/update";
    /**
     * 根据公司id统计完成订单的信息
     */
    public static final String COMPANY_ORDERFINISHEDINFO = "api/orders/findOrderFinishedBycompanyId";
    /**
     * 根据客户id查询最近完成订单
     */
    public static final String COUNT_FINISHED_BY_PASSENGER_DATE = "api/orders/countByPassenger";
    /**
     * 根据客户id查询正在执行的订单数量
     */
    public static final String COUNT_ACTIVED_BY_PASSENGER = "api/orders/queryRunOrder";
    /**
     * 根据客户id查询最近完成订单
     */
    public static final String FIND_LASTEDONE_FINISHED_BY_PASSENGER = "api/orders/findLastByPassenger";
    /**
     * 更具订单id查询查询轨迹
     */
    public static final String QUERY_ORDERORBIT = "api/orders/orderOrbit";
    /**
     * 根据服务人员id分页查询完成订单
     */
    public static final String QUERY_FINISHED_BY_EMPLOY = "api/orders/queryFinishOrderByEmployId";
    /**
     * 根据passenger查询未支付订单数量
     */
    public static final String COUNT_NOTPAY_BY_PASSENGER = "api/orders/countByPassengerId";
    /**
     * 查询服务人员奖励接口
     */
    public static final String FIND_REWARD = "api/orders/v4/findOrderByEmployId";
    /**
     * 报销
     */
    public static final String BAOXIAO = "api/orders/v4/baoxiao";
    /**
     * V4司机补单
     */
    public static final String ADDMORE = "api/orders/v4/addmore";
    /**
     * 结算前修改结算时间为当前时间
     */
    public static final String ADD_FINISHTIME = "api/orders/prepare";
    /**
     * 分页查询乘客订单.
     */
    public static final String FIND_ORDERS = "api/orders/findOrders.json?passengerId={passengerId}&appKey={appKey}";
    private static final Logger logger = LoggerFactory.getLogger(FreightApi.class);
    private static final String COUNT_RUNNINGS_NEW = "api/orders/countRunnings.json?passengerId={passengerId}&appKey={appKey}";
    @Value("${module.freight.url}")
    private String freightBaseURL;
    @Autowired
    private RestTemplate restTemplate;

    public String getFreightBaseURL() {

        return freightBaseURL.endsWith("/") ? freightBaseURL : freightBaseURL + "/";
    }

    public void setFreightBaseURL(String freightBaseURL) {
        this.freightBaseURL = freightBaseURL;
    }

    public RestTemplate getRestTemplate() {
        return restTemplate;
    }

    public void setRestTemplate(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    public String get(String apiurl, Map<String, String> kv, Setting setting) {
        kv.put("appKey", setting.getSecKey());

        String result = null;

        try {
            result = restTemplate.getForObject(apiurl, String.class, kv);
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            logger.error("HttpClientErrorException:code:{},status:{},body:{}", e.getStatusCode(),
                e.getStatusText(), e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            logger.error("HttpServerErrorException:{}", e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return result;

    }

    public String post(String apiurl, Map<String, String> kv, Setting setting) {

        kv.put("appKey", setting.getSecKey());

        String result = null;
        try {
            result = restTemplate.postForObject(apiurl, null, String.class, kv);
        } catch (HttpClientErrorException e) {
            logger.error("HttpClientErrorException:code:{},status:{},body:{}", e.getStatusCode(),
                e.getStatusText(), e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        } catch (HttpServerErrorException e) {
            logger.error("HttpServerErrorException:{}", e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        }

        return result;
    }

    public String postMultiValueMap(String apiurl, MultiValueMap<String, String> kv,
        Setting setting) {

        kv.add("appKey", setting.getSecKey());

        String result = null;
        try {
            result = restTemplate.postForObject(apiurl, kv, String.class);
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            logger.error("HttpClientErrorException:code:{},status:{},body:{}", e.getStatusCode(),
                e.getStatusText(), e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        } catch (HttpServerErrorException e) {
            logger.error("HttpServerErrorException:{}", e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        }

        return result;
    }

    public String put(String apiurl, Map<String, String> kv, Setting setting) {
        kv.put("appKey", setting.getSecKey());

        String result = null;
        try {
            restTemplate.put(apiurl, null, kv);
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            result = e.getResponseBodyAsString();
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            logger.error("HttpServerErrorException:{}", e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        }
        return result;

    }

    public String putMultiValueMap(String apiurl, MultiValueMap<String, String> kv,
        Setting setting) {

        kv.add("appKey", setting.getSecKey());

        String result = null;
        try {
            restTemplate.put(apiurl, kv);
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            result = e.getResponseBodyAsString();
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            logger.error("HttpServerErrorException:{}", e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        }
        return result;
    }

    public String delete(String apiurl, Map<String, String> kv, Setting setting) {
        kv.put("appKey", setting.getSecKey());

        String result = null;

        try {
            restTemplate.delete(apiurl, kv);
        } catch (HttpClientErrorException e) {
            result = e.getResponseBodyAsString();
        } catch (HttpServerErrorException e) {
            logger.error("HttpServerErrorException:{}", e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        }
        return result;
    }

    public String updateCarStatus(Long truckId, Long driverId, String driverName, Integer status,
        Setting setting) {
        StringBuilder builder = new StringBuilder();
        builder.append(this.getFreightBaseURL() + FreightApi.UPDATE_TRUCK
            + "?truckId={truckId}&appKey={appKey}");
        Map<String, String> kv = new HashMap<String, String>();
        kv.put("truckId", String.valueOf(truckId));
        kv.put("driverId", String.valueOf(driverId));
        kv.put("driverName", driverName);

        if (status != null) {
            builder.append("&status={status}");
            kv.put("status", String.valueOf(status));
        }

        builder.append("&driverId={driverId}");
        kv.put("driverId", String.valueOf(driverId));

        builder.append("&driverName={driverName}");
        kv.put("driverName", String.valueOf(driverName));

        String result = null;
        try {
            result = this.put(builder.toString(), kv, setting);

        } catch (HttpClientErrorException e) {
            result = e.getResponseBodyAsString();
        } catch (HttpServerErrorException e) {
            result = e.getResponseBodyAsString();
        }
        return result;
    }

    public Long countFinishedByPassengerAndFinishTime(Long passengerId,
        String orderFromSources, Date startDate, Date endDate, Setting setting) {
        long finishedTimes = 0;

        StringBuilder builder = new StringBuilder();
        builder.append(
            getFreightBaseURL() + FreightApi.COUNT_FINISHED_BY_PASSENGER_DATE + "?appKey={appKey}");
        Map<String, String> kv = new HashMap<String, String>();

        kv.put("passengerId", String.valueOf(passengerId));
        builder.append("&passengerId={passengerId}");

        if (StringUtils.isNotBlank(orderFromSources)) {
            kv.put("orderFromSources", String.valueOf(orderFromSources));
            builder.append("&orderFromSources={orderFromSources}");
        }

        kv.put("startTime", String.valueOf(startDate.getTime()));
        builder.append("&startTime={startTime}");

        if (null != endDate) {
            kv.put("endTime", String.valueOf(endDate.getTime()));
            builder.append("&endTime={endTime}");
        }

        String result = get(builder.toString(), kv, setting);
        if (StringUtils.isNotBlank(result)) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                finishedTimes = jo.getLong("data");
            }
        }
        return finishedTimes;
    }

    public Result<Order> selectLastedOneFinishedByPassenger(Long passengerId, Setting setting) {

        Result<Order> result = new Result<Order>();
        result.setSuccess(false);

        Order order = null;

        StringBuilder builder = new StringBuilder();
        builder.append(getFreightBaseURL() + FreightApi.FIND_LASTEDONE_FINISHED_BY_PASSENGER
            + "?passengerId={passengerId}&appKey={appKey}");
        Map<String, String> kv = new HashMap<String, String>();
        kv.put("passengerId", String.valueOf(passengerId));
        String resultStr = get(builder.toString(), kv, setting);

        if (null != resultStr) {
            JSONObject jo = new JSONObject(resultStr);
            Integer code = jo.getInt("code");
            if (code == 0) {
                Object object = jo.get("data");
                if (null != object && !object.toString().equals("null")) {
                    JSONObject data = jo.getJSONObject("data");
                    Gson gson = new GsonBuilder().setDateFormat(com.ybkj.daijia.constant.DateConstant.DATE_TIME_FORMATE).create();
                    order = gson.fromJson(data.toString(), Order.class);
                    result.setResult(order);
                }
                result.setSuccess(true);
            } else {
                result.setSuccess(false);
                result.setMessage(jo.getString("message"));
            }
        }
        return result;
    }

    public long countActiveByPassenger(Long passengerId, Setting setting) {
        long activedTimes = 0;

        StringBuilder builder = new StringBuilder();
        builder.append(
            getFreightBaseURL() + FreightApi.COUNT_ACTIVED_BY_PASSENGER + "?appKey={appKey}");
        Map<String, String> kv = new HashMap<String, String>();

        kv.put("passengerId", String.valueOf(passengerId));
        builder.append("&passengerId={passengerId}");

        String result = get(builder.toString(), kv, setting);
        if (StringUtils.isNotBlank(result)) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                activedTimes = jo.getLong("data");
            }
        }
        return activedTimes;
    }

    public Result<Order> baoxiao(Long orderId, BigDecimal money, Setting setting) {

        Result<Order> vo = new Result<Order>();

        MultiValueMap<String, String> kv = new LinkedMultiValueMap<String, String>();

        kv.add("orderId", String.valueOf(orderId));
        kv.add("baoxiaoMoney", String.valueOf(money));

        String result = postMultiValueMap(getFreightBaseURL() + FreightApi.BAOXIAO, kv, setting);

        if (StringUtils.isNotBlank(result)) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                vo.setSuccess(true);
            } else {
                String message = jo.getString("message");
                vo.setMessage(message);
            }
        } else {
            vo.setMessage("内部服务器错误");
        }

        return vo;

    }

    public Result<Order> findOneOrder(Long orderId, Setting setting) {

        Result<Order> vo = new Result<Order>();

        StringBuilder builder = new StringBuilder();
        builder.append(getFreightBaseURL() + FreightApi.QUERY_ORDER_ONE
            + "?orderId={orderId}&appKey={appKey}");
        Map<String, String> kv = new HashMap<String, String>();
        kv.put("orderId", String.valueOf(orderId));
        String result = get(builder.toString(), kv, setting);
        if (null != result) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                JSONObject data = jo.getJSONObject("data");
                Gson gson = new GsonBuilder().setDateFormat(com.ybkj.daijia.constant.DateConstant.DATE_TIME_FORMATE).create();
                Order order = gson.fromJson(data.toString(), Order.class);
                vo.setResult(order);
                vo.setSuccess(true);
            }
        }
        return vo;
    }

    public String post(String apiurl, MultiValueMap<String, String> kv, Setting setting) {
        kv.add("appKey", setting.getSecKey());

        Set<Entry<String, List<String>>> entries = kv.entrySet();

        Map<String, String> params = new HashMap<String, String>();
        for (Entry<String, List<String>> entry : entries) {
            List<String> values = entry.getValue();
            params.put(entry.getKey(), CollectionUtils.isEmpty(values) ? null : values.get(0));
        }

//      String sign = SignHelper.sign(SignHelper.buildSignMessage(params),zhuanAppkey);
//
//      kv.add("sign",sign);
//      kv.add("appId",zhuanAppid);

        RestTemplate rest = new RestTemplate();

        String result = null;
        try {
            result = rest.postForObject(apiurl, kv, String.class);
        } catch (HttpClientErrorException e) {
            e.printStackTrace();
            logger.error("HttpClientErrorException:code:{},status:{},body:{}", e.getStatusCode(),
                e.getStatusText(), e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        } catch (HttpServerErrorException e) {
            e.printStackTrace();
            logger.error("HttpServerErrorException:{}", e.getResponseBodyAsString());
            result = e.getResponseBodyAsString();
        }

        return result;
    }

    public Result<Order> addFinishTime(Long orderId, Setting setting) {

        Result<Order> vo = new Result<Order>();

        MultiValueMap<String, String> kv = new LinkedMultiValueMap<String, String>();

        kv.add("orderId", String.valueOf(orderId));

        String result = postMultiValueMap(getFreightBaseURL() + FreightApi.ADD_FINISHTIME, kv,
            setting);

        if (StringUtils.isNotBlank(result)) {
            JSONObject jo = new JSONObject(result);
            Integer code = jo.getInt("code");
            if (code == 0) {
                Boolean data = jo.getBoolean("data");
                vo.setSuccess(data);
                return vo;
            } else {
                String message = jo.getString("message");
                vo.setMessage(message);
            }
        } else {
            vo.setMessage("内部服务器错误");
        }

        return vo;

    }

    public Long selectCreateOrderNumber(Long passengerId, String appKey, Setting setting) {
        Long num = 0L;
        try {
            Map<String, String> kv = new HashMap<String, String>();
            kv.put("passengerId", String.valueOf(passengerId));
            kv.put("appKey", appKey);
            String result = get(getFreightBaseURL() + FreightApi.COUNT_RUNNINGS_NEW, kv, setting);
            if (StringUtils.isNotBlank(result)) {
                JSONObject jo = new JSONObject(result);
                Integer code = jo.getInt("code");
                if (code == 0) {
                    num = jo.getLong("data");
                }
            } else {
                num = (long) -1;
            }
        } catch (Exception ex) {
            logger.error(ex.getMessage());
        }
        return num;

    }

    public List<Map<String, Object>> findOrders(Long passengerId, Integer page, Integer rows,
        String appKey) {

        Map<String, String> kv = new HashMap<String, String>();
        StringBuilder builder = new StringBuilder();
        builder.append(getFreightBaseURL() + FreightApi.FIND_ORDERS);
        kv.put("passengerId", String.valueOf(passengerId));
        if (page != null) {
            kv.put("page", String.valueOf(page));
            builder.append("&page={page}");
        }
        if (rows != null) {
            kv.put("rows", String.valueOf(rows));
            builder.append("&rows={rows}");
        }
        kv.put("appKey", appKey);

        String string = restTemplate.getForObject(builder.toString(), String.class, kv);
        com.alibaba.fastjson.JSONObject jsonObject = JSON.parseObject(string);
        int code = jsonObject.getIntValue("code");

        Map<String, Object> map = new HashMap<String, Object>();

        map.put("code", code);
        map.put("msg", jsonObject.getString("message"));
        List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
        if (code == 0) {
            com.alibaba.fastjson.JSONObject json = jsonObject.getJSONObject("data");
            long total = json.getLong("total");
            List<Order> list = new ArrayList<Order>();

            JSONArray jsonArray = json.getJSONArray("rows");
            list = JSON.parseArray(jsonArray.toString(), Order.class);
            for (Order order : list) {
                Map<String, Object> orderMap = new HashMap<String, Object>();
                orderMap.put("id", order.getId());
                orderMap.put("created", order.getCreated().getTime());
                orderMap.put("orderNo", order.getOrderNo());
                orderMap.put("passengerId", order.getPassengerId());
                orderMap.put("passengerName", order.getPassengerName());
                orderMap.put("passengerPhone", order.getPassengerPhone());
                orderMap.put("employId", order.getEmployId());
                orderMap.put("employName", order.getEmployName());
                orderMap.put("employPhone", order.getEmployPhone());
                orderMap.put("employPhoto", order.getEmployPhoto());
                orderMap.put("employNo", order.getEmployNo());
                orderMap.put("employScore", order.getEmployScore());
                orderMap.put("truckTypeName", order.getTruckTypeName());
                orderMap.put("truckNumber", order.getTruckNumber());
                orderMap.put("companyId", order.getCompanyId());
                orderMap.put("companyName", order.getCompanyName());
                orderMap.put("status", order.getStatus());
                orderMap.put("startAddress", order.getStartAddress());
                orderMap.put("endAddress", order.getDestination());
                orderMap.put("serverTime", order.getStartTime().getTime());
                orderMap.put("wayPoints", order.getWaypoints());
                orderMap.put("review", order.getReview());
                if (order.getOrderReviews() != null) {
                    orderMap.put("orderScore", order.getOrderReviews().getScore());
                    orderMap.put("orderContent", order.getOrderReviews().getContent());
                }

                orderMap.put("realPay", formatDouble(order.getRealPay()));
                orderMap.put("budgetPay", formatDouble(order.getBudgetPay()));
                orderMap.put("preMileage", formatDouble(order.getPremileage()));
                orderMap.put("preMileagePrice", formatDouble(order.getPremileagePrice()));
                orderMap.put("preRunTimePrice", formatDouble(order.getPrerunTimePrice()));
                orderMap.put("preStartPrice", formatDouble(order.getPreStartPrice()));
                orderMap.put("preTravelTime", order.getPretravelTime());
                orderMap.put("payDetail", order.getPayDetail());
                orderMap.put("treatment", order.getTreatment());
                listMap.add(orderMap);
            }
            return listMap;
        }
        return listMap;
    }

    /**
     * 格式化double数字.
     */

    private Double formatDouble(Double dou) {
        try {
            DecimalFormat df = new DecimalFormat("######0.00");
            String format = df.format(dou);
            Double valueOf = Double.valueOf(format);
            return valueOf;
        } catch (Exception ex) {
            return dou;
        }
    }
}
